const app = getApp();
const common = require('../../../utils/common.js');
const api = require('../../../config/api.js');

var isSend = 0;

Page({
  data: {
    avatarUrl: '',
    nickname: '',
    memberNo: '',
    mobile: '',
    name: '',
    array: ['女', '男', '保密'],
    gender: 0,
    createTime: '',
    birthday: '',
    region: ['', '', '']
  },
  onLoad: function (options) {

  },
  onShow: function () {
    this.getMemberInfo();
  },
  getMemberInfo: function () {
    var that = this;
    var data = {};
    common.request(api.MemberInfo, data, 'get').then(function (data) {
      if (data.type == 'success') {
        var region = that.data.region;
        region[0] = data.data.province;
        region[1] = data.data.city;
        region[2] = data.data.district;
        that.setData({
          avatarUrl: data.data.avatarUrl,
          nickname: data.data.nickname,
          memberNo: data.data.memberNo,
          mobile: data.data.mobile,
          name: data.data.name,
          gender: parseInt(data.data.gender),
          createTime: data.data.createTime,
          birthday: data.data.birthday,
          region: region
        });
      }
    });
  },
  getname: function (e) {
    var name = e.detail.value;
    this.setData({
      name: name
    })
  },
  getmemberNo: function (e) {
    var memberNo = e.detail.value;
    this.setData({
      memberNo: memberNo
    })
  },
  //选择性别
  bindPickerChange: function (e) {
    this.setData({
      gender: e.detail.value
    })
  },
  //选择生日
  bindbirthDateChange: function (e) {
    this.setData({
      birthday: e.detail.value
    })
  },
  //切换地址
  bindRegionChange: function (e) {
    console.log(e.detail.value);
    this.setData({
      region: e.detail.value
    })
  },
  //提交信息
  tijiao: function (e) {
    var name = this.data.name;
    var gender = this.data.gender;
    var birthday = this.data.birthday;
    var region = this.data.region;
    var data = {
      name: name,
      gender: gender,
      birthday: birthday,
      province: region[0],
      city: region[1],
      district: region[2]
    }
    common.request(api.MemberInfoUpdate, data, 'POST').then(function (data) {
      if (data.type === 'success') {
        common.showSuccessToast(data.content);
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
        }, 1500);
      } else {
        common.showErrorToast(data.content);
      }
    });
  }
})